package com.xinqi.modules.sys.complaint.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.ComplaintTypeEnum;
import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.sys.complaint.dto.req.ComplaintHandlingDTO;
import com.xinqi.modules.sys.complaint.dto.req.ComplaintQueryDTO;
import com.xinqi.modules.sys.complaint.dto.rsp.ComplaintResultDTO;
import com.xinqi.modules.sys.complaint.service.ComplaintService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * ADMIN -- 聊天投诉
 *
 * @author: yyzhenn
 * @date: 2023/04/23
 */
@Validated
@RestController
@RequestMapping("/admin/complaint")
@RequiredArgsConstructor
public class ComplaintAdminController {
    private final ComplaintService complaintService;

    @Operation(summary = "投诉类型-枚举列表")
    @GetMapping("/type/list")
    public R<List<Map<String, String>>> typeList() {
        return R.data(ComplaintTypeEnum.getSelectList());
    }

    @Operation(summary = "聊天投诉-分页")
    @GetMapping("/page")
    public R<PageInfo<ComplaintResultDTO>> page(@ParameterObject ComplaintQueryDTO dto) {
        PageInfo<ComplaintResultDTO> page = complaintService.page(dto, dto);
        return R.data(page);
    }

    @Operation(summary = "聊天投诉-详情")
    @GetMapping("/info/{id}")
    public R<ComplaintResultDTO> info(@NotNull(message = "{complaint.id.not.blank}") @PathVariable("id") Long id) {
        return R.data(complaintService.findById(id));
    }


    @Operation(summary = "聊天投诉-处理")
    @PostMapping("/handling")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 处理聊天投诉", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> handling(@Validated @RequestBody ComplaintHandlingDTO dto) {
        dto.setOperationUserId(LoginHelper.getUserId());
        return R.data(complaintService.handling(dto));
    }

}
